import { easyClone } from '@/utils';
<!--
 * @Description:
 * @Author: wyh19
 * @Date: 2021-05-21
-->
<template>
  <el-form ref="form" :model="formData" :disabled="formDisabled" :rules="rules" label-width="80px"
           size="small" @validate="handleValidate">
    <el-form-item label="姓名" prop="name" class="field-wrapper">
      <el-input v-model="formData.name" v-compare:name="oldFormData" />
    </el-form-item>
    <el-form-item label="年龄" class="field-wrapper">
      <el-input v-model="formData.age" v-compare:age="oldFormData" />
    </el-form-item>
    <el-form-item label="学历" class="field-wrapper">
      <el-select v-model="formData.education"
                 v-compare:education.map="{oldFormData,map:composeOptions(educationList)}"
                 @change="$emit('field-change','education',$event)">
        <el-option v-for="item in educationList" :key="item.value" :value="item.value"
                   :label="item.label"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="性别" class="field-wrapper">
      <el-radio-group v-model="formData.gender"
                      v-compare:gender.map="{oldFormData,map:{1:'女',2:'男'}}">
        <el-radio :label="1">女</el-radio>
        <el-radio :label="2">男</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="爱好" class="field-wrapper">
      <el-checkbox-group v-model="formData.hobby"
                         v-compare:hobby.arrayMap="{oldFormData,map:composeOptions(hobbyList)}">
        <el-checkbox v-for="item in hobbyList" :key="item.value" :label="item.value">
          {{ item.label }}
        </el-checkbox>
      </el-checkbox-group>
    </el-form-item>
  </el-form>
</template>

<script>
import SuperFormMixin from '@/mixins/super-form-mixin'
export default {
  name: 'Form1',
  mixins: [SuperFormMixin],
  data() {
    return {
      educationList: [
        {
          label: '研究生',
          value: 1
        },
        {
          label: '本科',
          value: 2
        },
        {
          label: '大专',
          value: 3
        }
      ],
      hobbyList: [
        {
          label: '看书',
          value: 1
        },
        {
          label: '打游戏',
          value: 2
        },
        {
          label: '运动',
          value: 3
        }
      ],
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'change' }
        ]
      }
    }
  }
}
</script>

<style scoped lang="scss">
.field-wrapper {
  width: 320px;
}
</style>
